package com.example.sunlight.interneteverything.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.sunlight.interneteverything.R;

import java.net.Socket;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created by SunLight on 2017/8/18.
 */

public class ShopBase extends BaseAdapter {


    Context context;
    List<String[]> list;

    public ShopBase(Context context) {
        this.context = context;
    }

    public void setData(List<String[]> list) {

        if (list != null) {
            this.list = list;
        }

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {

        return list.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler = null;
        if (convertView == null) {
            hodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.list_shop_item, null);
            hodler.id = (TextView) convertView.findViewById(R.id.id);
            hodler.type = (TextView) convertView.findViewById(R.id.type);
            hodler.name = (TextView) convertView.findViewById(R.id.name);
            hodler.storage = (TextView) convertView.findViewById(R.id.storage);
            hodler.shelf = (TextView) convertView.findViewById(R.id.shelf);
            hodler.number = (TextView) convertView.findViewById(R.id.number);
            hodler.state = (TextView) convertView.findViewById(R.id.state);
            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }
        if (Integer.parseInt(list.get(position)[5]) < 3) {
            hodler.state.setTextColor(Color.RED);
        }
        hodler.id.setText(list.get(position)[0]);
        hodler.type.setText(list.get(position)[1]);
        hodler.name.setText(list.get(position)[2]);
        hodler.storage.setText(list.get(position)[3]);
        hodler.shelf.setText(list.get(position)[4]);
        hodler.number.setText(list.get(position)[5] + "件");
        hodler.state.setText(list.get(position)[6]);


        return convertView;
    }

    class ViewHodler {
        private TextView id;
        private TextView type;
        private TextView name;
        private TextView storage;
        private TextView shelf;
        private TextView number;
        private TextView state;
    }
}
